package com.mine.androidlearn.tempdb;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.mine.androidlearn.R;
import com.mine.androidlearn.common.base.BaseActivity;
import com.mine.androidlearn.common.db.DBHuInfo;
import com.mine.androidlearn.common.db.DbUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DBActivity extends BaseActivity {


    @BindView(R.id.tvShowWeather)
    TextView tvShowWeather;
    @BindView(R.id.btnGetWeather)
    Button btnGetWeather;
    @BindView(R.id.btnInsertDB)
    Button btnInsertDB;
    @BindView(R.id.btnQueryDB)
    Button btnQueryDB;
    @BindView(R.id.btnDeleteDB)
    Button btnDeleteDB;
    @BindView(R.id.btnUpdateDB)
    Button btnUpdateDB;

    private DbUtil mDbUtil;
    private int mCount=0;

    @Override
    protected void initVariables() {
        mDbUtil=new DbUtil(this);
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setContentView(R.layout.activity_db);

        ButterKnife.bind(this);
    }

    @Override
    protected void loadData() {

    }

    @OnClick({R.id.btnGetWeather, R.id.btnInsertDB, R.id.btnQueryDB, R.id.btnDeleteDB, R.id.btnUpdateDB})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btnGetWeather:
                break;
            case R.id.btnInsertDB:
                mCount++;
                DBHuInfo huInfo=new DBHuInfo();
                huInfo.setHuName("hu"+mCount);
                huInfo.setHuAge(26);
                huInfo.setHuSex("男");
                huInfo.setJob("IT");
                mDbUtil.insertHuInfo(huInfo);
                break;
            case R.id.btnQueryDB:
                List<DBHuInfo> list=mDbUtil.queryHuInfo();
                if(list.size()==0){
                    Toast.makeText(DBActivity.this,"没有数据",Toast.LENGTH_SHORT).show();
                    return;
                }
                Toast.makeText(DBActivity.this,list.get(0).getHuName(),Toast.LENGTH_SHORT).show();
                break;
            case R.id.btnDeleteDB:
                mDbUtil.deleteHuInfo("hu"+mCount);
                Toast.makeText(DBActivity.this,"已删除数据",Toast.LENGTH_SHORT).show();
                break;
            case R.id.btnUpdateDB:
                break;
        }
    }
}
